package net.softwarefabrik.bde.core.model.platform;

import net.softwarefabrik.bde.core.model.BDEException;
import net.softwarefabrik.bde.core.model.maven.RepositoryManager;
import net.softwarefabrik.bde.core.model.platform.internal.EquinoxPlatformProvider;
import net.softwarefabrik.bde.core.model.platform.internal.FelixPlatformProvider;

/**
 * Static factory class to create <code>PlatformProviders</code>.
 * 
 * @author Matthias Kuespert
 */
public class PlatformProviderFactory {

    private static final String PLATFORM_NAME_FELIX        = "Felix";

    private static final String PLATFORM_NAME_EQUINOX      = "Equinox";

    private static final String PLATFORM_NAME_KNOPFLERFISH = "Knopflerfish";

    /**
     * @return An array of <code>String</code>s holding the names of the
     *         supported OSGi platforms.
     */
    public static String[] getPlatforms() {
        return new String[] {
                PLATFORM_NAME_FELIX,
                PLATFORM_NAME_EQUINOX,
                PLATFORM_NAME_KNOPFLERFISH
        };
    }

    /**
     * Retrieves a provider for the given platform name.
     * 
     * @param platform The name of an OSGi platform.
     * @return A <code>PlatformProvider</code>
     * @throws BDEException if the given platform is not supported.
     */
    public static PlatformProvider getProvider(String platform, RepositoryManager repositoryManager) throws BDEException {
        if (platform.equals(PLATFORM_NAME_FELIX)) {
            return new FelixPlatformProvider(repositoryManager);
        } else if (platform.equals(PLATFORM_NAME_EQUINOX)) {
            return new EquinoxPlatformProvider(repositoryManager);
        } else if (platform.equals(PLATFORM_NAME_KNOPFLERFISH)) {
            throw new BDEException("Sorry, platform " + platform + " is not yet provided.");
        }
        throw new BDEException("No provider found for platform " + platform);
    }
}
